package com.hugedata.cdnserver.common;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.log4j.Logger;

import com.hugedata.imsp.jabberc.IMSPClient;
import com.hugedata.pd.PD;

public final class SpackClient
{
    private final Logger LOGGER = Logger.getLogger(getClass());
    private static Logger ossLogger = Logger.getLogger(SpackClient.class);

    private IMSPClient client;

    private final static Lock lock = new ReentrantLock();

    public SpackClient()
    {
        LOGGER.info("SpackClient in...");

        lock.lock();
        try
        {
            client = IMSPClient.getInstance();
        }
        finally
        {
            lock.unlock();
        }

        LOGGER.info("SpackClient out...");
    }

    public IMSPClient getSpackClient()
    {
        return client;
    }

    /**
     * 
     * @Title: isMCSConnected
     * @Description: 判断MCS连接是否成功
     * @author Wangxiaoming
     */
    public boolean isMCSConnected()
    {
        boolean isConnectedFlag = false;
        try
        {
            isConnectedFlag = PD.getSingleton().isMCSConnected();
        }
        catch (Exception e)
        {
            LOGGER.error("PD.getSingleton().isMCSConnected() Exception", e);
            isConnectedFlag = false;
        }
        return isConnectedFlag;
    }
}
